<script>
function isMobile() {
    return (/phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|webOS|android/i.test(navigator.userAgent))
}
var _isMobile=isMobile();
_h=h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
console.log(_isMobile);
//if(sWidth>540){sWidth=540;}
var _rate=(sWidth/750);
if(h<_rate*1246){
  h=_rate*1246;
}
function setKe(cname, cvalue){
  var cname='a1'+cname;
    var d = new Date();
    d.setTime(d.getTime() + (6*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getke(cname) {
  var cname='a1'+cname;
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
         }
         if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
         }
     }
    return "";
}
function chinanum(num){
    var china = new Array('零','一','二','三','四','五','六','七','八','九');  
    var arr = new Array();
    var num=num+'';
    var english = num.split("")  
    for(var i=0;i<english.length;i++){
        arr[i] = china[english[i]];
    }
    if(2 == english.length){
        if('一' == arr[0]){
          return ('十'+arr[1]);
        }else{
          return (arr[0]+'十'+arr[1]);
        }
    }else{
      return arr.join("")  
    }
}
Array.prototype.shuffle = function(){
    let array = this;
    let len = array.length;
    for (let i = len - 1; i > 0; i--) {
      let j = Math.floor(Math.random() * (i + 1));
      [array[i], array[j]] = [array[j], array[i]];
    }
}
var _uid='<?php echo $uid ?>';
var _uPhone='';
var _uZu='';
var endDate = new Date();
var min=endDate.getMinutes();
//endDate.setMinutes(min+30);
endDate.setMinutes(min+<?php echo $m; ?>);
endDate.setSeconds(min+<?php echo $s; ?>);
end = endDate.getTime();

$(function(){
  $(".p1").show().addClass("fade-in");
  $('.container, .page').width(sWidth).height(h);
  $('.p-b').height(_rate*1206);

  $('.p1-t1').css({"top":_rate*72});

 
  $('.p1-jin').width(_rate*510).height(_rate*150).css({"top":_rate*520, "left":_rate*120});

  $('#p2-zu').width(_rate*346).height(_rate*78).css({"top":_rate*252, "left":_rate*290});
  $('#p2-school').width(_rate*346).height(_rate*78).css({"top":_rate*350, "left":_rate*290});
  $('#p2-name').width(_rate*346).height(_rate*78).css({"top":_rate*446, "left":_rate*288}); 
  $('#p2-idcard').width(_rate*346).height(_rate*78).css({"top":_rate*546, "left":_rate*288}); 
  $('#p2-phone').width(_rate*346).height(_rate*78).css({"top":_rate*644, "left":_rate*288});
  $('.p2-next').width(_rate*346).height(_rate*90).css({"top":_rate*810, "left":_rate*200});
  
  $('.p3-next').width(_rate*346).height(_rate*140).css({"top":_rate*836, "left":_rate*200}); 

  $('.dx-abcd').css({"top":_rate*406});
  $('.dx-li').height(_rate*60).css({"line-height":_rate*60+'px','margin-bottom':_rate*6});
  $('.dx-li-ico').width(_rate*51).height(_rate*46).css({"top":_rate*6, "left":0});
  $('.dx-li span, .pduan-li span').css({"margin-left":_rate*66});
  $('.dx-dan').css({'margin-top':_rate*22});
  $('.dx-a, .dx-b, .dx-c, .dx-d, .pan-a, .pan-b').width(_rate*106);
  $('.dx-b').css({"left":_rate*118});
  $('.dx-c').css({"left":_rate*235});
  $('.dx-d').css({"left":_rate*352});

  
   
  $('.dx-up, .pan-up, .tian-up').width(_rate*325).css({"top":_rate*910, "left":_rate*60});
  $('.dx-next, .pan-next, .tian-next').width(_rate*325).css({"top":_rate*910, "left":_rate*380});
  $('.xze-title, .tian-title').height(_rate*68).css({"top":_rate*136,'line-height':_rate*72+'px'});

  $('.pan-abcd').css({"top":_rate*452});
  $('.pan-dan').css({'margin-top':_rate*36});
  $('.pan-a').css({"left":_rate*103});
  $('.pan-b').css({"left":_rate*248});

  $(".tktxt").width(_rate*120);
  
  
  $('.time-t1, .time-t2').height(_rate*35).css({"top":_rate*80, "left":_rate*84});
  $('.time-t2').width(_rate*586);

  $('.time-t3').width(_rate*200).height(_rate*50).css({"top":_rate*80, "right":_rate*100,'line-height':_rate*37+'px'});

   
   var _shuffle14Cookie=getke('sz_shuffle14Cookie');
   var _shuffle8Cookie=getke('sz_shuffle8Cookie');
   var _shuffle20Cookie=getke('sz_shuffle20Cookie');
   var _userCurStepCookie=getke('sz_userCurStepA'); //当前步骤
   var _userIdCookie=getke('sz_userId'); 
   var _userPhoneCookie=getke('sz_phone');
    
    if ('' != _userIdCookie) {
      _uid=_userIdCookie;
    }
    if ('' != _userPhoneCookie) {
      _uPhone=_userPhoneCookie;
    }

   if('' == _shuffle20Cookie){
      var _shuffle20=[];
      for(var i=1;i<=20;i++){
        _shuffle20.push(i);
      }
      _shuffle20.shuffle();
      setKe('sz_shuffle20Cookie', _shuffle20);
   }else{
     var _shuffle20=_shuffle20Cookie.split(",");
   }

   if('' == _shuffle14Cookie){
      var _shuffle14=[];
      for(var i=1;i<=14;i++){
        _shuffle14.push(i);
      }
      _shuffle14.shuffle();
      setKe('sz_shuffle14Cookie', _shuffle14);
   }else{
     var _shuffle14=_shuffle14Cookie.split(",");
   }
   if('' == _shuffle8Cookie){
      var _shuffle8=[];
      for(var i=1;i<=8;i++){
        _shuffle8.push(i);
      }
      _shuffle8.shuffle();
      setKe('sz_shuffle8Cookie', _shuffle8);
   }else{
     var _shuffle8=_shuffle8Cookie.split(",");
   }
console.log(_shuffle8);
  console.log(_shuffle20);
  console.log(_shuffle14);
var _curId=0; //答题题目id
var _showId=_shuffle20[0];
$(".xze-t"+_showId+", .dx-t"+_showId).show();
var _dxData={}; 
var _panData={};
var _tianData={};
if('' != _shuffle20Cookie){
    if('dxtm' == _userCurStepCookie && '' != _userPhoneCookie && '' != _userIdCookie){
        var _tmDataStoreCookie=getke('sz_tmData');
        var _tmKeyStoreCookie=getke('sz_tmKey');
        if("" != _tmDataStoreCookie){
          var _tmpTmData=_tmDataStoreCookie.split(",");
          var _tmpTmKey=_tmKeyStoreCookie.split(",");
          for(var _i=0;_i<_tmpTmData.length;_i++){
             _dxData[_tmpTmKey[_i]]=_tmpTmData[_i];
             _curId++;
          }
        }
        $(".xze-bt, .dx-abcd").hide();
        _showId=_shuffle20[_curId-1];
        $(".xze-t"+_showId+", .dx-t"+_showId).show();
        $(".xze-title").html("选择题（ "+(_curId+1)+" / 20 ）");
        
        for(var _i=0;_i<_curId;_i++){
          _showId=_shuffle20[_i];
          $(".dx-t"+_showId+" .dx-"+_dxData[_showId]+"1").attr("src","<?php echo $url; ?>/img/b-r.png");
          $(".dx-t"+_showId+" .dx-"+_dxData[_showId]+"2").attr("src","<?php echo $url; ?>/img/b-"+_dxData[_showId]+"1.png");
        }
        console.log('_dxData:'+_dxData);
        $(".p1").hide();
        $(".xze").show();
   }
   
   if('pan' == _userCurStepCookie && '' != _userPhoneCookie && '' != _userIdCookie){
        var _tmDataStoreCookie=getke('sz_tmData');
        var _tmKeyStoreCookie=getke('sz_tmKey');
        if("" != _tmDataStoreCookie){
          var _tmpTmData=_tmDataStoreCookie.split(",");
          var _tmpTmKey=_tmKeyStoreCookie.split(",");
          for(var _i=0;_i<_tmpTmData.length;_i++){
             _panData[_tmpTmKey[_i]]=_tmpTmData[_i];
             _curId++;
          }
        }

        _showId=_shuffle14[_curId];
       console.log(_panData);
       $(".xze-title").html("判断题（ "+(_curId+1)+" / 14 ）");
       $(".pan-bt, .pan-abcd").hide();
       $(".pan-t"+_showId+", .pan-t"+_showId).show();

       for(var _i=0;_i<_curId;_i++){
          _showId=_shuffle14[_i];
          $(".pan-t"+_showId+" .pan-"+_panData[_showId]+"1").attr("src","<?php echo $url; ?>/img/b-r.png");
          $(".pan-t"+_showId+" .pan-"+_panData[_showId]+"2").attr("src","<?php echo $url; ?>/img/b-"+_panData[_showId]+"1.png");
        }
        $(".p1").hide();
        $(".pan").show();
        console.log('_panData:'+_panData); 
   }

   if('tian' == _userCurStepCookie && '' != _userPhoneCookie && '' != _userIdCookie){
        var _tmDataStoreCookie=getke('sz_tmData');
        var _tmData2StoreCookie=getke('sz_tmData2');
        var _tmKeyStoreCookie=getke('sz_tmKey');

        if("" != _tmDataStoreCookie){
          var _tmpTmData=_tmDataStoreCookie.split(",");
          var _tmpTmData2=_tmData2StoreCookie.split(",");
          var _tmpTmKey=_tmKeyStoreCookie.split(",");
          for(var _i=0;_i<_tmpTmData.length;_i++){
             _tianData[_tmpTmKey[_i]]={1:decodeURI(_tmpTmData[_i]),2:decodeURI(_tmpTmData2[_i])};
             _curId++;
          }
        }
        
       $(".tian-title").html("填空题（ "+(_curId+1)+" / 14 ）");
       $(".tian-bt").hide();
       $(".tian-t"+_showId).show();

       for(var _i=0;_i<_curId;_i++){
          _showId=_shuffle8[_i];
          $(".tian-t"+_showId+" .tk-1").val(_tianData[_showId][1]);
          $(".tian-t"+_showId+" .tk-2").val(_tianData[_showId][2]);
        } 
        $(".p1").hide();
        $(".tian").show();
       console.log('_tianData:'+_tianData); 
   }

   if('p3' == _userCurStepCookie && '' != _userPhoneCookie && '' != _userIdCookie){
        $(".p1").hide();
        $(".p3").show();
   }
   
   if('finish' == _userCurStepCookie && '' != _userPhoneCookie && '' != _userIdCookie){
        $(".p1").hide();
        $(".tipwc").show();
   }
  

}





   $(".dx-a").click(function(){
       _resetABCD('a');
   });
   $(".dx-b").click(function(){
       _resetABCD('b');
   });
   $(".dx-c").click(function(){
       _resetABCD('c');
   });
   $(".dx-d").click(function(){
       _resetABCD('d');
   });

    
   $(".dx-next").click(function(){
       _curId++;
       $(".xze-title").html("选择题（ "+(_curId+1)+" / 20 ）");
       $(".xze-bt, .dx-abcd").hide();
       _showId=_shuffle20[_curId];
      $(".xze-t"+_showId+", .dx-t"+_showId).show();
      
       
       var _tmData=[];
       var _tmKey=[];  
       $.each(_dxData,function(key,value) {
            _tmKey.push(key);
            _tmData.push(value);
        }); 
        setKe('sz_tmData', _tmData);
        setKe('sz_tmKey', _tmKey);
        setKe('sz_userCurStepA', 'dxtm');
        _userCurStepCookie='dxtm';
        if(_curId > 19){
          $(".xze").fadeOut();
          $(".pan").fadeIn();
          _curId=0;
          _showId=_shuffle14[_curId];
         $(".pan-t"+_showId+", .pan-t"+_showId).show();
         $(".xze-title").html("判断题（ 每题 2 分 ）");
         setKe('sz_userCurStepA', 'pan');
         _userCurStepCookie='pan';
         setKe('sz_tmData', []);
         setKe('sz_tmKey', []);
          $.post("./api/?c=setdan", {tm:_dxData,op:_uid,ph:_uPhone}, function(data){}, "json");
        }
        

   });
   $(".dx-up").click(function(){
       if(0 == _curId){return;}
       if(_curId < 0){return;}
       _curId--;
       $(".xze-title").html("选择题（ "+(_curId+1)+" / 20 ）");
       $(".xze-bt, .dx-abcd").hide();
       _showId=_shuffle20[_curId];
       $(".xze-t"+_showId+", .dx-t"+_showId).show();
   });
   function _resetABCD(_type){
      _showId=_shuffle20[_curId];
      _dxData[_showId]=_type;
      console.log(_dxData);
      $(".dx-t"+_showId+" .dx-a1, .dx-t"+_showId+" .dx-b1, .dx-t"+_showId+" .dx-c1, .dx-t"+_showId+" .dx-d1").attr("src","<?php echo $url; ?>/img/b-h.png");
      $(".dx-t"+_showId+" .dx-a2").attr("src","<?php echo $url; ?>/img/b-a.png");
      $(".dx-t"+_showId+" .dx-b2").attr("src","<?php echo $url; ?>/img/b-b.png");
      $(".dx-t"+_showId+" .dx-c2").attr("src","<?php echo $url; ?>/img/b-c.png");
      $(".dx-t"+_showId+" .dx-d2").attr("src","<?php echo $url; ?>/img/b-d.png");
      $(".dx-t"+_showId+" .dx-"+_type+"1").attr("src","<?php echo $url; ?>/img/b-r.png");
      $(".dx-t"+_showId+" .dx-"+_type+"2").attr("src","<?php echo $url; ?>/img/b-"+_type+"1.png");
   }
   
   
   //_showId=_shuffle14[_curId];
   //$(".pan-t"+_showId+", .pan-t"+_showId).show();
   $(".pan-a").click(function(){
      _showId=_shuffle14[_curId];
      _panData[_showId]='a';
      console.log(_showId);
      $(".pan-t"+_showId+" .pan-b1").attr("src","<?php echo $url; ?>/img/b-h.png");
      $(".pan-t"+_showId+" .pan-b2").attr("src","<?php echo $url; ?>/img/b-b.png");
       
      $(".pan-t"+_showId+" .pan-a1").attr("src","<?php echo $url; ?>/img/b-r.png");
      $(".pan-t"+_showId+" .pan-a2").attr("src","<?php echo $url; ?>/img/b-a1.png");
        
   });
   $(".pan-b").click(function(){
       _showId=_shuffle14[_curId];
       _panData[_showId]='b';
      $(".pan-t"+_showId+" .pan-a1").attr("src","<?php echo $url; ?>/img/b-h.png");
      $(".pan-t"+_showId+" .pan-a2").attr("src","<?php echo $url; ?>/img/b-a.png");

      $(".pan-t"+_showId+" .pan-b1").attr("src","<?php echo $url; ?>/img/b-r.png");
      $(".pan-t"+_showId+" .pan-b2").attr("src","<?php echo $url; ?>/img/b-b1.png");
      
   });

   $(".pan-next").click(function(){
       _curId++;
       _showId=_shuffle14[_curId];
       console.log(_panData);
       $(".xze-title").html("判断题（ "+(_curId+1)+" / 14 ）");
       $(".pan-bt, .pan-abcd").hide();
       
      $(".pan-t"+_showId+", .pan-t"+_showId).show();

       var _tmData=[];
       var _tmKey=[];  
       $.each(_panData,function(key,value) {
            _tmKey.push(key);
            _tmData.push(value);
        }); 
        setKe('sz_tmData', _tmData);
        setKe('sz_tmKey', _tmKey);
        setKe('sz_userCurStepA', 'pan');
        _userCurStepCookie='pan';
        if(_curId > 13){
          $(".pan").hide();
          $(".tian").show();
          _curId=0;
         $(".tian-title").html("填空题（ 每题 4 分 ）");
         $(".tian-bt").hide();
         _showId=_shuffle8[_curId];
         $(".tian-t"+_showId).show();
         setKe('sz_userCurStepA', 'tian');
         _userCurStepCookie='tian';
         setKe('sz_tmData', []);
         setKe('sz_tmKey', []);
          $.post("./api/?c=setpan", {tm:_panData,op:_uid,ph:_uPhone}, function(data){
         
          }, "json");
        }

    });

   $(".pan-up").click(function(){
       if(0 == _curId){return;}
       if(_curId < 0){return;}
       _curId--;
       $(".xze-title").html("判断题（ "+(_curId+1)+" / 14 ）");
       $(".pan-bt, .pan-abcd").hide();
       _showId=_shuffle14[_curId];
       $(".pan-t"+_showId+", .pan-t"+_showId).show();
   });
   

   

    _showId=_shuffle8[_curId];
   $(".tian-t"+_showId).show();

   $(".tian-next").click(function(){

       _showId=_shuffle8[_curId];
       var _txtA=$(".tian-t"+_showId+' .tk-1').val();
       var _txtB=$(".tian-t"+_showId+' .tk-2').val();
       _tianData[_showId]={1:_txtA,2:_txtB};
      console.log(_tianData);
       _curId++;
       _showId=_shuffle8[_curId];
      
      var _tmData=[];
      var _tmData2=[];
      var _tmKey=[];
      $.each(_tianData,function(key,value) {
            //_tmKey.push(key);
            //_tmData.push(value);
            _tmKey.push(key);
            _tmData.push(encodeURI(value[1]));
            _tmData2.push(encodeURI(value[2]));
            //var _tmp=encodeURI(value[1]);
            //var _tmp=encodeURI(value[2]);
        });  
        setKe('sz_tmData', _tmData);
        setKe('sz_tmData2', _tmData2);
        setKe('sz_tmKey', _tmKey);
        setKe('sz_userCurStepA', 'tian');
        _userCurStepCookie='tian';

      $(".tian-title").html("填空题（ "+(_curId+1)+" / 8 ）");
      $(".tian-bt").hide();
       
      $(".tian-t"+_showId).show();
      if(_curId > 7){
          setKe('sz_userCurStepA', 'finish');
           _userCurStepCookie='finish';
          $(".tian").hide();
          $(".tipwc").show();
          $.post("./api/?c=settian", {tm:_tianData,op:_uid,ph:_uPhone}, function(data){
         
          }, "json");
        }
       
    });
    
    $(".tian-up").click(function(){
       if(0 == _curId){return;}
       if(_curId < 0){return;}
       _curId--;
       $(".tian-title").html("填空题（ "+(_curId+1)+" / 14 ）");
       $(".tian-bt").hide();
       _showId=_shuffle8[_curId];
       $(".tian-t"+_showId).show();
   });


   $('.tktxt').bind('input propertychange', function() {
        var $this = $(this);
        var text_length = getByteLen($this.val());//获取当前文本框的长度
       // console.log(text_length);
        if(sWidth > 720){
          var current_width = parseInt(text_length/2) *18;
          current_width=current_width+18;
        }else{
          var current_width = parseInt(text_length/2) *12;
          current_width=current_width+12;
        }
        if(current_width > _rate*120){
          $this.css("width",current_width+"px");
        }
        //console.log(current_width)
    }); 
   function getByteLen(val) {
        var len = 0;
        for (var i = 0; i < val.length; i++) {
            var a = val.charAt(i);
            if (a.match(/[^\x00-\xff]/ig) != null) {//\x00-\xff→GBK双字节编码范围
                len += 2;
            }
            else {
                len += 1;
            }
        }
        return len;
    }

  $(".p1-jin").click(function(){
    $(".p1").hide();
    $(".p2").fadeIn();
  });
  $(".p2-next").click(function(){
     var _zu=$("#p2-zu").val();
     var _school=$("#p2-school").val();
     var _name=$("#p2-name").val();
     var _idcard=$("#p2-idcard").val();
     var _phone=$("#p2-phone").val();
     if('' == _zu){
         _popMsg("请选择组别");
         return; 
     }
     if('' == _school){
         _popMsg("请选择学校");
         return; 
     }
     if('' == _name){
         _popMsg("请输入学生姓名");
           return;  
    }
    if('' == _idcard){
         _popMsg("请输入身份证");
           return;  
    }
    if('' == _phone){
         _popMsg("请输入手机号");
           return;  
    }
    if('小学组' == _zu){
      _uZu='xiao';
    }else{
      _uZu='zhong';
    }
    
    _uPhone=_phone;
    $.post("./api/?c=setu", {uid:_uid,n:_name,idc:_idcard,ph:_phone,zu:_zu,school:_school}, function(data){
          console.log(data);
          if('y' == data.s){
            $(".p2").fadeOut(400);
            $(".p3").fadeIn(600);
            setKe('sz_phone', _phone); 
            setKe('sz_userId', _uid);
            setKe('sz_userCurStepA', 'p3');

            //初始化小学组题目 

          }
    }, "json");


  });

  $('.p3-next').click(function(){
    $(".p3").hide();
    $(".xze").fadeIn();
  });
 
  function _popMsg(msg){
    $(".weui-msg").html(msg);
        $(".js_dialog").show();
  }   
  $(".weui-btn").click(function(){
        $(".js_dialog").hide();
  });



  var _zongwidth=_rate*586;
  var _zongTime=60*20*1000;
  function countTime(){
    var date = new Date();  
    var now = date.getTime();
    var leftTime = end-now; 
    var m,s; 
    if (leftTime >= 0){
      m = Math.floor(leftTime/1000/60%60);
      s = Math.floor(leftTime/1000%60);
      var _tmpS=':'+s;
      if(s<10){
        _tmpS=':0'+s;
      }
      console.log(leftTime);
      var _percent=1 - leftTime/_zongTime + 0.02;
      if(_percent>1){_percent=1;}
      
      $(".time-t1").width(_percent*_zongwidth);
      

      $(".time-t3").html(m + _tmpS );
      setTimeout(countTime,1000); 
    }else{
      $(".time-t3").html("00:00");
      _tmTMType='stop';
      _tmTimeId=0;
      $(".tipshijian").show();
      console.log('end');
    }
  }
  countTime();

    
  $(".tipshijian").click(function(){
    $(".tipshijian").hide();
    $(".tipwc").show();

    if('tian' == _userCurStepCookie){
      $.post("./api/?c=settian", {tm:_tianData,op:_uid,ph:_uPhone}, function(data){}, "json");
    }
    if('dxtm' == _userCurStepCookie){
      $.post("./api/?c=setdan", {tm:_dxData,op:_uid,ph:_uPhone}, function(data){}, "json");
    }
    if('pan' == _userCurStepCookie){
       $.post("./api/?c=setpan", {tm:_panData,op:_uid,ph:_uPhone}, function(data){}, "json");
    }
 
    setKe('sz_userCurStepA', 'finish');
  });
   
    
});
</script>